package beanstao.util.store.domainobject;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import beanstao.util.Sber;
import beanstao.util.id.Id;
import beanstao.util.interfaces.to.IToXPath;
import beanstao.util.interfaces.to.IToXmlElement;
import beanstao.util.store.database.Fields;


@SuppressWarnings("serial")
public abstract class XmlDomain extends Domain implements IToXmlElement, IToXPath
{
	public XmlDomain(Fields fields, Id modifiorId, Id newDomainId)
	{
		super(fields, modifiorId, newDomainId);
	}

	public XmlDomain(Fields fields, Id modifiorId)
	{
		super(fields, modifiorId);
	}

	public XmlDomain(Fields fields)
	{
		super(fields);
	}

	@Override
	public Element toXmlElement()
	{
		Element element = DocumentHelper.createElement(_fields.getName());// this.getClass().getSimpleName());
		for (String key : _filedKeyValueMap.keySet())
			element.addAttribute(key, _filedKeyValueMap.get(key).toString());
		return element;
	}

	@Override
	public String toXPath()
	{
		Sber sber = Sber.ME("//").append(this.getFields().getName());
		for (String key : _filedKeyValueMap.keySet())
			sber.append("[@").append(key).append("='").append(_filedKeyValueMap.get(key)).append("']");
		return sber.toString();
	}

}
